import Vue from 'vue'
import VueRouter from 'vue-router'
/* 
//引入对应组件
import Login from '../views/Login/Login.vue'  //登录
import Reg from '../views/Reg/Reg.vue'        //注册
import Main from '../views/Main/Main.vue'     //首页
import Home from '../views/Menus/Home/Home.vue'     //二级路由  主页模块
import UserInfo from '../views/Menus/User/UserInfo.vue'  //二级路由  基本资料模块
import UserAvatar from '../views/Menus/User/UserAvatar.vue' //二级路由  更换头像  模块
import UserPwd from '../views/Menus/User/UserPwd.vue' //二级路由  重置密码  模块
import ArtCate from '../views/Menus/Article/ArtCate.vue' //二级路由  文章分类  模块
import ArtList from '../views/Menus/Article/ArtList.vue' //二级路由  文章添加  模块
 */


//  注册路由
Vue.use(VueRouter)
//添加路由规则
const routes = [
  //注册路由配置
  {
    path:'/reg',
    name:'reg',
    //正常写法
    // component:导入的组件名

    //路由懒加载模式  写法
    component:()=>import('../views/Reg/Reg.vue')
  },
  //登录的路由配置
  {
    path:'/login',
    name:'login',
    component:()=>import('../views/Login/Login.vue')
  },
  //首页的路由配置
  {
    path:'/',
    name:'main',
    component:()=>import('@/views/Main/Main.vue'),
    redirect:'/home', //重定向到主页/home
    children:[
      //二级路由的嵌套使用,二级路由path 不用加斜杠
      {
        path:'home',
        name:'home',
        component:()=>import('@/views/Menus/Home/Home.vue')
      },
      {
        path:'user-info',
        name:'userInfo',
        component:()=>import('../views/Menus/User/UserInfo.vue')
      },
      {
        path:'user-avatar',
        name:'userAvatar',
        component:()=>import('../views/Menus/User/UserAvatar.vue')
      },
      {
        path:'user-pwd',
        name:'userPwd',
        component:()=>import('../views/Menus/User/UserPwd.vue')
      },
      {
        path:'art-cate',
        name:'artCate',
        component:()=>import('../views/Menus/Article/ArtCate.vue')
      },
      {
        path:'art-list',
        name:'artList',
        component:()=>import('../views/Menus/Article/ArtList.vue')
      },
    ]
  }
]
//创建路由实例
const router = new VueRouter({
  routes
})
// VueRouter.prototype.push: push函数要求不能重复 跳转路由
//解决办法,就是改写 VueRouter中的push函数,但需要保留之前的功能
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (to) {
  return VueRouterPush.call(this, to).catch(err => err)
}
//暴露   路由
export default router
